package com.yycx.module.bus.provider.handler.sbreturn;

import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.module.bus.client.entity.*;
import org.springframework.stereotype.Component;

/**
 * 待退垫付款列表
 *
 * @author zyf
 */
@Component("noSbReturnPageListHandler")
public class NoSbReturnPageListHandler implements PageInterceptor<BusOrderDetails> {


    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        cq.clear();
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        String paymentNo = params.get("paymentNo");
        cq.select(BusOrderDetails.class,"orderDetailsId", "salePrice", "saleNum", "saleAmount","supplierPayBond","supplierBondPayDate","returnDate","returnAmount");
        cq.select(BusOrder.class,"orderId", "supplierBondType", "customBondType", "sendDate", "orderNo");
        cq.select(BusSupplier.class, "supplierName");
        cq.select(BusCustom.class, "customName");
        cq.select(BusDrugs.class, "drugsName", "drugsSpec");
        cq.eq("bod.companyId", OpenHelper.getCompanyId());
        if(FlymeUtils.isNotEmpty(paymentNo)) {
            cq.like(BusOrder.class, "orderNo",paymentNo);
        }
        cq.eq(BusOrderDetails.class, "supplierId");
        //垫付款已支付
        cq.eq("bod.supplierBondState", CommonConstants.INT_2);
        cq.isNull("bod.returnDianfuId");
        if (FlymeUtils.isNotEmpty(beginDate)) {
            cq.ge(BusOrder.class, "sendDate", beginDate);
        }
        if (FlymeUtils.isNotEmpty(endDate)) {
            cq.le(BusOrder.class, "sendDate", endDate);
        }
        cq.eq(BusOrderDetails.class, "orderId");
        cq.orderByDesc("bod.createTime");
    }


}
